package cn.tedu._06interceptor.config;

import cn.tedu._06interceptor.interceptors.MyInterceptor1;
import cn.tedu._06interceptor.interceptors.MyInterceptor2;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //策略一：默认拦截所有请求
        /*registry.addInterceptor(new MyInterceptor1());*/
        //策略二：拦截指定请求【一个或多个】比如只拦截登录和注册
        /*registry.addInterceptor(new MyInterceptor1())
                .addPathPatterns("/v1/users/login","/v1/users/reg");*/
        //策略三：拦截指定模块，拦截用户模块所有请求
        /*registry.addInterceptor(new MyInterceptor1())
                .addPathPatterns("/v1/users/**");*/
        //策略四;只拦截除登录功能之外的所有请求
        /*registry.addInterceptor(new MyInterceptor1())
                .addPathPatterns("/v1/users/**")
                .excludePathPatterns("/v1/users/login");*/
        //多拦截器使用
        registry.addInterceptor(new MyInterceptor1());
        registry.addInterceptor(new MyInterceptor2());

    }
}
